package com.spa.interfaces.admin;

import com.spa.application.command.admin.MassageServiceAddCommand;
import com.spa.application.command.admin.MassageServiceEditCommand;
import com.spa.application.command.admin.OnOffCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.MassageListExportDTO;
import com.spa.application.dto.admin.MassageServiceDTO;
import com.spa.application.dto.admin.MassageServiceListDTO;
import com.spa.application.dto.shop.ShopServiceDTO;
import com.spa.application.query.admin.MassageServiceQuery;
import com.spa.application.service.admin.MassageServiceApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("admin/message")
public class MassageServiceController extends BaseController {

    @Autowired
    private MassageServiceApplicationService messageServiceApplication;

    @PostMapping("add")
    public ResponseMessage queryMassagistFinance(@RequestBody MassageServiceAddCommand command) {
        messageServiceApplication.addMassageService(command);
        return responseHelper.success();
    }

    @PostMapping("edit")
    public ResponseMessage edit(@Validated @RequestBody MassageServiceEditCommand command) {
        messageServiceApplication.edit(command);
        return responseHelper.success();
    }

    @PostMapping("detail")
    public ResponseMessage<MassageServiceDTO> detail(@RequestBody MassageServiceQuery query) {
        return responseHelper.success(messageServiceApplication.detail(query));
    }

    @PostMapping("page")
    public ResponseMessage<PageResult<MassageServiceListDTO>> page(@RequestBody MassageServiceQuery query) {
        return responseHelper.success(messageServiceApplication.page(query));
    }

    @PostMapping("exportMessageList")
    public void exportMessageList(HttpServletResponse response, @RequestBody MassageServiceQuery query) throws Exception {
        List<MassageListExportDTO> massageListExportDTOS = messageServiceApplication.getMassageServiceList(query);
        exportQueryResult(response, massageListExportDTOS, "服务项目", "服务项目", MassageListExportDTO.class);
    }

    @PostMapping("onOff")
    public ResponseMessage onOff(@RequestBody OnOffCommand command) {
        messageServiceApplication.onOff(command);
        return responseHelper.success();
    }

    @PostMapping("queryServiceList")
    public ResponseMessage<List<ShopServiceDTO>> queryServiceList() {
        return responseHelper.success(messageServiceApplication.serviceList());
    }

}
